'use strict'

const {
  DataTypes,
  Model,
  Op
} = require('../../../azeroth').sequelize;
class FlawInfo extends Model {}

const initFlawData = (sequelize_aim) => {
  FlawInfo.init(
    {
      uid: {
        field: 'uid',
        type: DataTypes.INTEGER,
        allowNull: false,
        primaryKey: true,
        autoIncrement: true,
      },
      job_id: {
        field: 'job_id',
        type: DataTypes.INTEGER,
      },
      panel_id: {
        field: 'panel_id',
        type: DataTypes.STRING,
      },
      class_id: {
        field: 'class_id',
        type: DataTypes.INTEGER,
      },
      center_pos_md: {
        field: 'center_pos_md',
        type: DataTypes.INTEGER,
      },
      center_pos_cd: {
        field: 'center_pos_cd',
        type: DataTypes.INTEGER,
      },
      length_md: {
        field: 'length_md',
        type: DataTypes.INTEGER,
      },
      length_cd: {
        field: 'length_cd',
        type: DataTypes.INTEGER,
      },
      contours: {
        field: 'contours',
        type: DataTypes.STRING,
      },
      gen_time: {
        field: 'gen_time',
        type: DataTypes.BIGINT,
      },
      gen_time_str: {
        field: 'gen_time_str',
        type: DataTypes.STRING,
      },
      save_path: {
        field: 'save_path',
        type: DataTypes.STRING,
      },
      ui_show_text: {
        field: 'ui_show_text',
        type: DataTypes.STRING,
      },
      area: {
        field: 'area',
        type: DataTypes.INTEGER,
      },
      diameter: {
        field: 'diameter',
        type: DataTypes.INTEGER,
      },
      camera_id: {
        field: 'camera_id',
        type: DataTypes.INTEGER,
      },
      flaw_class_type: {
        field: 'flaw_class_type',
        type: DataTypes.STRING,
      },
      lot_id: {
        field: 'lot_id',
        type: DataTypes.STRING,
      },
    }, {
      freezeTableName: true,
      sequelize: sequelize_aim,
      modelName: 'flaw',
      timestamps: false
    }
  )
}

FlawInfo.uploadFlawInfo = async (data) => {
  let res = await FlawInfo.bulkCreate([data], {
    updateOnDuplicate: ['uid', ' job_id', ' flaw_class_type']
  });
  return res;
}

module.exports = {
  FlawInfo,
  initFlawData
};